#!/usr/bin/env python
# encoding: utf-8
"""
window.py

Created by Morgan Quirk on 2007-08-09.
"""

class Window:
    def __init__(self, size, game_size=(-1,-1), start_position=(0,0)):
        self.width, self.height = size
        self.x1, self.y1 = start_position
        self.x2 = self.x1 + self.width
        self.y2 = self.y1 + self.height
        self.gx , self. gy = game_size
        
        if self.gx == -1:
            self.gx = self.x2
        if self.gy == -1:
            self.gy = self.y2
        
    def center(self, position):
        x, y = position
        self.x1 = min(max(x - self.width  / 2, 0), self.gx)
        self.y1 = min(max(y - self.height / 2, 0), self.gy)
        self.x2 = self.x1 + self.width
        self.y2 = self.y1 + self.height
        
    def is_on_screen(self, rect):
        x1, y1, x2, y2 = rect
        if x2>self.x1 and x1<self.x2 and y2>self.y1 and y1<self.y2:
            return True
        return False